package com.wenjh.jdmzt.service;

import android.database.sqlite.SQLiteDatabase;

import com.wenjh.jdmzt.AndroidKit;
import com.wenjh.jdmzt.service.dao.UserDao;
import com.wenjh.jdmzt.service.model.User;

public class UserService extends BaseService {
	private UserDao userDao = null;
	public UserService() {
		userDao = new UserDao(AndroidKit.getApp().getSqliteInstance());
	}
	
	public UserService(SQLiteDatabase db) {
		userDao = new UserDao(db);
	}
	
	public void saveUser(User user) {
		if(checkUserExist(user.id)) {
			userDao.update(user);
		} else {
			userDao.insert(user);
		}
	}
	
	public User findUser(String userId) {
		return userDao.get(userId);
	}
	
	public void findUser(String userId, User user) {
		userDao.get(user, userId);
	}
	
	public boolean checkUserExist(String userId) {
		return userDao.checkExsit(userId);
	}
}
